<template>
    <div>
      <div>
      <el-button type="success" @click="returnBook">显示待完成</el-button><!-- <el-button type="success" @click="tobereviewed">待审核</el-button> -->
      </div>
      <div class="tixingziti">
        <span style="font-size: 15px;color:chocolate;">黄色代表超期</span>
      </div>
      <br>
      <el-table :data="tableData" border style="width: 100%" :row-class-name="tableRowClassName">
        <el-table-column prop="username" label="借阅用户" width="130" align="center">
        </el-table-column>
        <el-table-column prop="bookName" label="借阅书籍" width="130" align="center">
        </el-table-column>
        <el-table-column prop="bookId" label="书籍编号" width="130" align="center">
        </el-table-column>
        <el-table-column prop="borrowTime" label="借阅时间" width="200" align="center">
        </el-table-column>
        <el-table-column prop="returnTime" label="归还期限" width="200" align="center">
        </el-table-column>  
        <el-table-column prop="completionTime" label="还书日期" width="200" align="center">
        </el-table-column>  
        <el-table-column label="状态" width="130" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.isAgree == 1">{{ scope.row.isFinish == 1 ? "已还书":"未还书" }}</div>
            <div v-if="scope.row.isAgree == 0">{{ scope.row.isReturn == 2 ? "还书待审核":"借书待批准" }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="auditer" label="审核人" width="130" align="center">
        </el-table-column>
        <!-- <el-table-column label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button :disabled="scope.row.isReturn == '0' ? false : true" type="danger" size="mini" @click="frozen(scope.row.id)">提醒还书</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <br>
      <el-pagination background layout="total,sizes,prev,pager,next,jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :total="total"
      :current-page="currentPage"
      :page-size="pageSize"
      :page-sizes="[5,10,15,20,30,40,50]"></el-pagination>
    </div>
  </template>
  
  <script>
  import axios from "axios"
  export default {
    data () {
      return {
        tableData:[],
        total:0,
        currentPage:1,
        pageSize:10,
        finish:true,
        json:{},
      }
    },
    methods: {
      /*  控制表格颜色 */
      tableRowClassName({row}) {
        if(row.completionTime == null){
          return 'success-row';
        }
        if(row.completionTime > new Date || row.isAgree == 0){
          return 'warning-row';
        }else{
          return 'success-row';
        }
      },

      /* 显示已完成 */
      returnBook(){
          if(this.finish == true){
            this.$set(this.json,"isFinish",0)
            this.$set(this.json,"page",this.currentPage)
            this.finish = !this.finish
            this.getborrowinfo()
          }else{
            this.$delete(this.json,"isFinish")
            this.$set(this.json,"page",this.currentPage)
            this.finish = !this.finish
            this.getborrowinfo()
          }
      },
      getborrowinfo(){
        axios.post(this.url + "/borrow/borrowlist",this.json).then((res) => {
        if(res.data.code == 1){
          this.tableData = res.data.data.records
          this.total = res.data.data.total
        }
      }).catch(() => {
        this.$message.error("信息加载失败")
      });
      },
      handleSizeChange(val){
      this.$set(this.json,"pageSize",val)
      axios.post(this.url + "/borrow/borrowlist",this.json).then((res) => {
        if(res.data.code == 1){
          this.tableData = res.data.data.records
          this.total = res.data.data.total
        }
      }).catch(() => {
        this.$message.error("信息加载失败")
      });
      },

      handleCurrentChange(val){
        this.$set(this.json,"page",val)
      axios.post(this.url + "/borrow/borrowlist",this.json).then((res) => {
        if(res.data.code == 1){
          this.tableData = res.data.data.records
          this.total = res.data.data.total
        }
      }).catch(() => {
        this.$message.error("信息加载失败")
      });
      },

    },
    mounted () {
      this.$set(this.json,"page",this.currentPage)
      this.$set(this.json,"pageSize",this.pageSize)
      axios.post(this.url + "/borrow/borrowlist",this.json).then((res) => {
        if(res.data.code == 1){
          this.tableData = res.data.data.records
          this.total = res.data.data.total
        }
      }).catch(() => {
        this.$message.error("信息加载失败")
      });
    }
  }
  </script>
  
  <style scoped>
      .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #ffff;
  }

  .tixingziti{
    position: absolute;
    right: 5%;
    top:15%;
  }
  </style>